package com.hgk.wanwan.main.fragment.whatfragment.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.common.handmark.pulltorefresh.library.internal.BallBaseAdapter;
import com.common.nostra13.universalimageloader.core.DisplayImageOptions;
import com.common.nostra13.universalimageloader.core.ImageLoader;
import com.hgk.common.common.ui.view.CircularImageView;
import com.hgk.common.common.util.LoadImageDisplayOption;
import com.hgk.wanwan.main.fragment.whatfragment.model.WhatGridBean;

import width.hgk.wanwan.R;

/**
 * Created by lenovo on 2016/9/30.
 */
public class WhatGridAdapter extends BallBaseAdapter{
    private DisplayImageOptions mDisplayImageOptions;
    private Context mContext;
    private LayoutInflater mInflater;

    public WhatGridAdapter(Context context) {
        this.mContext = context;
        mDisplayImageOptions = LoadImageDisplayOption.getDefaultIcon(R.drawable.icon);
        mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHoudler vh = null;
        if (convertView==null){
            vh = new ViewHoudler();
            convertView = mInflater.inflate(R.layout.what_gridview_item,null);
            vh.mClIvHeardPic = (CircularImageView) convertView.findViewById(R.id.cIv_what_grid_item_headpic);
            vh.mNickName = (TextView) convertView.findViewById(R.id.tv_what_frag_grid_item_nickname);
//            vh.mTags = (TagFlowLayout) convertView.findViewById(R.id.tags_what_grid_item);
            convertView.setTag(vh);
        }else{
            vh = (ViewHoudler) convertView.getTag();
        }
        WhatGridBean.Data data = (WhatGridBean.Data) getItem(position);
        if (data!=null){
            ImageLoader.getInstance().displayImage(data.getHeadpic(),vh.mClIvHeardPic,mDisplayImageOptions);
            if (!TextUtils.isEmpty(data.getNickname())){
                vh.mNickName.setText(data.getNickname());
            }else{
                vh.mNickName.setText("无昵称");
            }
            if(data.getTags().size()>0){
                //TODO 设置标签的样式与个数

            }else{
                //TODO 当推荐人没有标签时设定为默认标签或者为空标签

            }
        }
        return convertView;
    }

    public class ViewHoudler{
        private CircularImageView mClIvHeardPic;
        private TextView mNickName;
//        private TagFlowLayout mTags;
    }
}
